import {SET_USERINFO,DELETE_USERINFO} from '../action-type'

let _uinfo = JSON.parse(localStorage.getItem('uinfo'));
let _token = localStorage.getItem('admin_jwt_token')
let initState = {
    uinfo: _uinfo || {},
    token:_token,
    isLogin: _uinfo && _token ? true : false
}
export default function (preState = initState,action) {
    const {type, data} = action;
    let newState;
    switch (type) {
        case SET_USERINFO:
            newState = {uinfo: data.userInfo, token:data.token, isLogin: true};
            return newState;
        case DELETE_USERINFO:
            newState = {uinfo: {}, _token:'', isLogin: false};
            return newState;
        default:
            return preState;
    }
}